<?php

/**
 * @author quangthinh
 * @copyright 2012
 */

class Qtadmin_Model_Menu extends Zend_Db_Table_Abstract{
    public $_name = 'tbl_menu';
    public $_primary = 'menu_id';
    public $_sequence = true;
    
    /**
     * Lay tat ca
     */
    public function getAll()
    {
        $se = $this->select();
        $result = $this->fetchAll($se);
        if($result)
            return $result->toArray();
        return false;
    }
    
     /**
     * Lay tat ca active
     */
    public function getOn()
    {
        $se = $this->select();
        $se->where('active = ?', 1);
        $result = $this->fetchAll($se);
        if($result)
            return $result->toArray();
        return false;
    }
    
    /**
     * Lay tat ca ko active
     */
    public function getOff()
    {
        $se = $this->select();
        $se->where('active = ?', 0);
        $result = $this->fetchAll($se);
        if($result)
            return $result->toArray();
        return false;
    }
    
    /**
     * Lay tat ca thoa dieu kien
     */
    public function getWhere($where, $val)
    {
        $se = $this->select();
        $se->where($where, $val);
        $result = $this->fetchAll($se);
        if($result)
            return $result->toArray();
        return false;
    }
    
    /**
     * Lay 1 thoa dieu kien
     */
    public function getWhereOne($where, $val)
    {
        $se = $this->select();
        $se->where($where, $val);
        $result = $this->fetchAll($se);
        if($result)
            return $result->toArray();
        return false;
    }
    
    /**
     * Tat active
     */
     public function offActive($id)
     {
        $arr = array('active'=>'0');
        $result = $this->update($arr, "$this->_primary = $id");
         if($result)
            return true;
        return false;
     }
     
     /**
     * Mo active
     */
     public function onActive($id)
     {
        $arr = array('active'=>'1');
        $result = $this->update($arr, "$this->_primary = $id");
         if($result)
            return true;
        return false;
     }
     
     /**
     * Insert
     */
     public function qtInsert($arr)
     {
        $result = $this->insert($arr);
        if($result)
            return true;
        return false;
        
     }
     
      /**
     * Insert
     */
     public function qtDelete($where)
     {
        $result = $this->delete($where);
        if($result)
            return true;
        return false;
        
     }
     
    
}

